package app.fugema.shop.main.setting.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.base.common.app.LoginUtils;
import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.ada.SingleUniversalAdapter;
import com.base.common.view.base.BaseTitleActivity;
import com.base.common.view.base.OnGetDataListener;
import com.base.common.view.widget.statelayout.StateLayout;
import com.base.common.viewmodel.BaseViewObserver;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ActivityRecyclerviewBinding;
import app.fugema.shop.main.setting.model.ChatMsgResult;
import app.fugema.shop.main.setting.vm.SettingUserVM;

/**
 * 系统消息 列表
 */
public class SysMsgActivity extends BaseTitleActivity<ActivityRecyclerviewBinding, SettingUserVM> implements OnGetDataListener
{

    private SingleUniversalAdapter<ChatMsgResult.ChatBean> adapter;

    public static void start(Context context)
    {
        Intent intent = new Intent(context, SysMsgActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview);
    }

    @Override
    protected void initView()
    {

        setTitle("消息");
        adapter = new SingleUniversalAdapter<ChatMsgResult.ChatBean>()
        {
            @Override
            public int getLayoutId()
            {
                return R.layout.item_chat_msg_view;
            }

            @Override
            public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, ChatMsgResult.ChatBean bean)
            {
                super.onItemClick(view, adapter, onclickType, position, bean);
                WebActivity.start(SysMsgActivity.this ,bean.getCustomerServiceLink() );
            }
        };

        binding.rvRecyclerView.setAdapter(adapter);

        viewUtils.setRefreshStateLayout(binding.rvRecyclerView, this, this);

        viewUtils.getStateLayout().setTipText(StateLayout.EMPTY, "暂无消息");

    }


    @Override
    protected void initData()
    {
        onGetData(1);
    }


    @Override
    public void onGetData(int pn)
    {
        String userkey = LoginUtils.getToken();
        viewModel.getChatsMsg( userkey).observe(this, new BaseViewObserver<LiveDataWrapper<ChatMsgResult>>(viewUtils.getStateLayout())
        {
            @Override
            protected void onSuccess(LiveDataWrapper<ChatMsgResult> data)
            {
                // data.data
                viewUtils.setDataListRefreshLayout(adapter, pn, 15,data.data.getList());
            }

            @Override
            public boolean isEmptyData(LiveDataWrapper<ChatMsgResult> data)
            {
                return  UIUtils.isEmpty(data.data);
            }

            @Override
            public boolean isRefreshLayoutData()
            {
                return true;
            }
        });
    }


}
